package com.jzoom.zoom.admin.controllers;

import com.jzoom.zoom.admin.models.AdminDaoModel;
import com.jzoom.zoom.dao.Page;
import com.jzoom.zoom.dao.Record;
import com.jzoom.zoom.web.annotations.JsonResponse;
import com.jzoom.zoom.web.annotations.Mapping;
import com.jzoom.zoom.web.annotations.Param;

import java.util.List;
import java.util.Map;

public class BaseDaoController<T extends AdminDaoModel> extends AbstractDaoController<T> implements AdminController {


	@Mapping(value="index",method= {Mapping.GET})
	public Object index(){
		return null;
	}

	@Mapping(value="add",method= {Mapping.GET})
	public Object add() {
		return null;
	}
	
	@Mapping(value="edit",method= {Mapping.GET})
	public Object edit() {
		return null;
	}
	
	@Mapping(value="list",method= {Mapping.POST})
	@JsonResponse
	public List<Record> list(@Param(name="@")Map<String, Object> params){
		return model.getList(  params );
	}
	
	
	
	@Mapping(value="index",method= {Mapping.POST})
	@JsonResponse
	public Page<Record> index(@Param(name="@")Map<String, Object> params){
		return model.getPage(  params );
	}
	
	/**
	 * 新增
	 * @param data
	 */
	@JsonResponse
	@Mapping(value="add",method= {Mapping.POST})
	public void add( 
			@Param( comment="提交的表单信息",name=Param.BODY)  Map<String, Object> data
		) {
		model.add( data );
	}
	
	
	/**
	 * 获取详细
	 * @param id
	 * @return
	 */
	@JsonResponse
	@Mapping(value = "get/{id}", method = {Mapping.POST})
	public Record get(@Param(name="{id}",comment="id") String id) {
		return model.get(id);
	}
	
	/**
	 * 修改
	 * @param data
	 */
	@JsonResponse
	@Mapping(value="put/{id}",method= {Mapping.POST})
	public void put( @Param(name="@") Map<String, Object> data, @Param(name="{id}") String id ) {
		 model.put(id,data);
	}
	
	@Mapping(value="del/{id}",method= {Mapping.POST})
	@JsonResponse
	public int del(@Param(name="{id}")String id) {
		return model.del(id);
	}
}
